﻿// HSS.Forms.MsgBox.cs
// ----------------------------------------------------------------------------
// Licensed under the MIT license
// http://www.opensource.org/licenses/mit-license.html
// ----------------------------------------------------------------------------
// HighSpeed-Solutions, LLC
// Copyright (c) 2001-2010
// ----------------------------------------------------------------------------
// File:       MsgBox.cs
// Author:     HSS\gbanta
// Created:    08/12/2010
// Modified:   12/24/2010
// ----------------------------------------------------------------------------
namespace HSS.Forms
{
	#region Using Directives
	using System;
	using System.Collections.Generic;
	using System.Drawing;
	using System.Windows.Forms;
	#endregion

	#region MsgBox
	/// <summary>
	/// A Custom MsgBox for displaying Messages and provides support
	/// for a custom list of button. This Form is also used in conjunction
	/// with the <see cref="MessageService"/> class
	/// </summary>
	public partial class MsgBox : Form
	{
		#region Enums

		#region Icons
		/// <summary>
		/// The Icons available for the MsgBox
		/// </summary>
		public enum Icons
		{
			/// <summary>
			/// An icon representing an error
			/// </summary>
			Error,
			/// <summary>
			/// An icon representing file explorer
			/// </summary>
			Explorer,
			/// <summary>
			/// An icon representing a find
			/// </summary>
			Find,
			/// <summary>
			/// An icon representing general information
			/// </summary>
			Information,
			/// <summary>
			/// An icon representing internet explorer
			/// </summary>
			InternetExplorer,
			/// <summary>
			/// An icon representing mail
			/// </summary>
			Mail,
			/// <summary>
			/// An icon representing media
			/// </summary>
			Media,
			/// <summary>
			/// An icon representing printing
			/// </summary>
			Print,
			/// <summary>
			/// An icon representing a question
			/// </summary>
			Question,
			/// <summary>
			/// An icon representing an empty recycle bin
			/// </summary>
			RecycleBinEmpty,
			/// <summary>
			/// An icon representing a full recycle bin
			/// </summary>
			RecycleBinFull,
			/// <summary>
			/// An icon representing the start of something
			/// </summary>
			Start,
			/// <summary>
			/// An icon representing the end of something
			/// </summary>
			Stop,
			/// <summary>
			/// An icon representing a User(s)
			/// </summary>
			User,
			/// <summary>
			/// An icon representing a warning
			/// </summary>
			Warning
		}
		#endregion

		#region Buttons
		/// <summary>
		/// The Buttons available for the MsgBox
		/// </summary>
		public enum Buttons
		{
			/// <summary>
			/// The AbortRetryIgnore buttons combination
			/// </summary>
			AbortRetryIgnore,
			/// <summary>
			/// The OK button only
			/// </summary>
			OK,
			/// <summary>
			/// The OKCancel buttons combination
			/// </summary>
			OKCancel,
			/// <summary>
			/// The RetryCancel buttons combination
			/// </summary>
			RetryCancel,
			/// <summary>
			/// The YesNo buttons combination
			/// </summary>
			YesNo,
			/// <summary>
			/// The YesNoCancel buttons combination
			/// </summary>
			YesNoCancel
		}
		#endregion

		#endregion

		#region Constructor
		/// <summary>
		/// Default Constructor
		/// </summary>
		private MsgBox()
		{
			InitializeComponent();
			this.Text = string.Empty;
			LoadIcons();
		}
		/// <summary>
		/// Default Constructor
		/// </summary>
		private MsgBox(string title)
		{
			InitializeComponent();
			this.Text = title;
			LoadIcons();
		}
		static MsgBox()
		{
			fontPrototype = new Font("Segoe UI", 9f, FontStyle.Regular);
			LoadIcons();
			MessageService.DoBeep = true;
		}
		static void LoadIcons()
		{
			if (!initialized)
			{
				icons.Add(Icons.Error, HSS.Forms.Resources.Error);
				icons.Add(Icons.Explorer, HSS.Forms.Resources.Explorer);
				icons.Add(Icons.Find, HSS.Forms.Resources.Find);
				icons.Add(Icons.Information, HSS.Forms.Resources.Information);
				icons.Add(Icons.InternetExplorer, HSS.Forms.Resources.InternetExplorer);
				icons.Add(Icons.Mail, HSS.Forms.Resources.Mail);
				icons.Add(Icons.Media, HSS.Forms.Resources.Media);
				icons.Add(Icons.Print, HSS.Forms.Resources.Print);
				icons.Add(Icons.Question, HSS.Forms.Resources.Question);
				icons.Add(Icons.RecycleBinEmpty, HSS.Forms.Resources.RecycleBinEmpty);
				icons.Add(Icons.RecycleBinFull, HSS.Forms.Resources.RecycleBinFull);
				icons.Add(Icons.Start, HSS.Forms.Resources.Start);
				icons.Add(Icons.Stop, HSS.Forms.Resources.Stop);
				icons.Add(Icons.User, HSS.Forms.Resources.User);
				icons.Add(Icons.Warning, HSS.Forms.Resources.Warning);

				initialized = true;
			}
		}
		#endregion

		#region Fields

		private static Dictionary<Icons, Icon> icons = new Dictionary<Icons, Icon>();
		private static Font fontPrototype;
		private static bool initialized;

		private List<Button> customButtons = new List<Button>();
		private int acceptButton;
		private int cancelButton;

		#endregion

		#region Properties
		/// <summary>
		/// Gets the index of the button pressed.
		/// </summary>
		public int Result
		{
			get { return _result; }
		} int _result = -1;
		#endregion

		#region Static Methods

		/// <summary>
		/// Show a message box.
		/// </summary>
		/// <param name="message">The message to show</param>
		/// <returns>A <see cref="DialogResult"/> indicates the users selection</returns>
		public static DialogResult Show(string message)
		{
			return Show(message, Application.ProductName, Buttons.OK, Icons.Information);
		}
		/// <summary>
		/// Show a message box.
		/// </summary>
		/// <param name="message">The message to show</param>
		/// <param name="title">The Title for the message box</param>
		/// <returns>A <see cref="DialogResult"/> indicates the users selection</returns>
		public static DialogResult Show(string message, string title)
		{
			return Show(message, title, Buttons.OK, Icons.Information);
		}
		/// <summary>
		/// Show a message box.
		/// </summary>
		/// <param name="message">The message to show</param>
		/// <param name="title">The Title for the message box</param>
		/// <param name="button">The button(s) to show</param>
		/// <returns>A <see cref="DialogResult"/> indicates the users selection</returns>
		public static DialogResult Show(string message, string title, Buttons button)
		{
			return Show(message, title, button, Icons.Information);
		}
		/// <summary>
		/// Show a message box.
		/// </summary>
		/// <param name="message">The message to show</param>
		/// <param name="title">The Title for the message box</param>
		/// <param name="button">The button(s) to show</param>
		/// <param name="defaultButton">The button that should be selected by default</param>
		/// <returns>A <see cref="DialogResult"/> indicates the users selection</returns>
		public static DialogResult Show(string message, string title, Buttons button, int defaultButton)
		{
			return Show(message, title, button, Icons.Information);
		}
		/// <summary>
		/// Show a message box.
		/// </summary>
		/// <param name="message">The message to show</param>
		/// <param name="title">The Title for the message box</param>
		/// <param name="button">The button(s) to show</param>
		/// <param name="icon">The icon to show</param>
		/// <returns>A <see cref="DialogResult"/> indicates the users selection</returns>
		public static DialogResult Show(string message, string title, Buttons button, Icons icon)
		{
			message = StringParser.Parse(message);
			title = StringParser.Parse(title);

			using (MsgBox msgBox = new MsgBox(title))
			{
				msgBox.lblMessage.Text = message;
				msgBox.InitButtons(button);
				msgBox.InitIcon(icon);
				msgBox.pbxIcon.Image = new Bitmap(msgBox.frmIcon.ToBitmap(), 38, 38);
				SetWidth(msgBox);
				SetHeight(msgBox, message);
				return msgBox.ShowDialog(MessageService.MainForm);
			}
		}
		/// <summary>
		/// Show a message box.
		/// </summary>
		/// <param name="message">The message to show</param>
		/// <param name="title">The Title for the message box</param>
		/// <param name="button">The button(s) to show</param>
		/// <param name="icon">The icon to show</param>
		/// <param name="defaultButton">The button that should be selected by default</param>
		/// <returns>A <see cref="DialogResult"/> indicates the users selection</returns>
		public static DialogResult Show(string message, string title, Buttons button, Icons icon, int defaultButton)
		{
			if (defaultButton < 0)
				defaultButton = 0;

			message = StringParser.Parse(message);
			title = StringParser.Parse(title);

			using (MsgBox msgBox = new MsgBox(title))
			{
				msgBox.lblMessage.Text = message;
				msgBox.InitButtons(button, defaultButton);
				msgBox.InitIcon(icon);
				msgBox.pbxIcon.Image = new Bitmap(msgBox.frmIcon.ToBitmap(), 38, 38);
				SetWidth(msgBox);
				SetHeight(msgBox, message);
				return msgBox.ShowDialog(MessageService.MainForm);
			}
		}

		/// <summary>
		/// Show a message box with custom buttons.
		/// </summary>
		/// <param name="message">The message to show</param>
		/// <param name="title">The Title for the message box</param>
		/// <param name="buttons">A string array containing the text for the custom list of buttons</param>
		/// <param name="acceptButton">Indicates the button that is the Forms AcceptButton</param>
		/// <param name="cancelButton">Indicates the button that is the Forms CancelButton</param>
		/// <param name="icon">The icon to show</param>
		/// <returns>The index of the button that was pressed</returns>
		public static int Show(string message, string title, string[] buttons, int acceptButton, int cancelButton, Icons icon)
		{
			message = StringParser.Parse(message);
			title = StringParser.Parse(title);

			using (MsgBox msgBox = new MsgBox(title))
			{
				msgBox.lblMessage.Text = message;
				msgBox.acceptButton = acceptButton;
				msgBox.cancelButton = cancelButton;
				msgBox.ShowCustomButton(buttons);
				msgBox.InitIcon(icon);
				msgBox.pbxIcon.Image = new Bitmap(msgBox.frmIcon.ToBitmap(), 38, 38);
				SetWidth(msgBox);
				SetHeight(msgBox, message);
				msgBox.ShowDialog(MessageService.MainForm);
				return msgBox.Result;
			}
		}
		/// <summary>
		/// Show a message box with custom buttons.
		/// </summary>
		/// <param name="message">The message to show</param>
		/// <param name="title">The Title for the message box</param>
		/// <param name="buttons">A string array containing the text for the custom list of buttons</param>
		/// <param name="acceptButton">Indicates the button that is the Forms AcceptButton</param>
		/// <param name="cancelButton">Indicates the button that is the Forms CancelButton</param>
		/// <param name="icon">The icon to show</param>
		/// <param name="defaultButton">The button that should be selected by default</param>
		/// <returns>The index of the button that was pressed</returns>
		public static int Show(string message, string title, string[] buttons, int acceptButton, int cancelButton, Icons icon, int defaultButton)
		{
			if (defaultButton >= buttons.Length)
				throw new ArgumentOutOfRangeException("The default buttons is outside the range of available buttons.");

			if (defaultButton < 0)
				defaultButton = buttons.Length - 1;

			message = StringParser.Parse(message);
			title = StringParser.Parse(title);

			using (MsgBox msgBox = new MsgBox(title))
			{
				msgBox.lblMessage.Text = message;
				msgBox.acceptButton = acceptButton;
				msgBox.cancelButton = cancelButton;
				msgBox.ShowCustomButton(buttons, defaultButton);
				msgBox.InitIcon(icon);
				msgBox.pbxIcon.Image = new Bitmap(msgBox.frmIcon.ToBitmap(), 38, 38);
				SetWidth(msgBox);
				SetHeight(msgBox, message);
				msgBox.ShowDialog(MessageService.MainForm);
				return msgBox.Result;
			}
		}
		/// <summary>
		/// Show a message box with custom buttons.
		/// </summary>
		/// <param name="message">The message to show</param>
		/// <param name="buttons">A string array containing the text for the custom list of buttons</param>
		/// <param name="acceptButton">Indicates the button that is the Forms AcceptButton</param>
		/// <param name="cancelButton">Indicates the button that is the Forms CancelButton</param>
		/// <param name="icon">The icon to show</param>
		/// <returns>The index of the button that was pressed</returns>
		public static int Show(string message, string[] buttons, int acceptButton, int cancelButton, Icons icon)
		{
			message = StringParser.Parse(message);

			using (MsgBox msgBox = new MsgBox(Application.ProductName))
			{
				msgBox.lblMessage.Text = message;
				msgBox.acceptButton = acceptButton;
				msgBox.cancelButton = cancelButton;
				msgBox.ShowCustomButton(buttons);
				msgBox.InitIcon(icon);
				msgBox.pbxIcon.Image = new Bitmap(msgBox.frmIcon.ToBitmap(), 38, 38);
				SetWidth(msgBox);
				SetHeight(msgBox, message);
				msgBox.ShowDialog(MessageService.MainForm);
				return msgBox.Result;
			}
		}
		/// <summary>
		/// Show a message box with custom buttons.
		/// </summary>
		/// <param name="message">The message to show</param>
		/// <param name="buttons">A string array containing the text for the custom list of buttons</param>
		/// <param name="acceptButton">Indicates the button that is the Forms AcceptButton</param>
		/// <param name="cancelButton">Indicates the button that is the Forms CancelButton</param>
		/// <param name="icon">The icon to show</param>
		/// <param name="defaultButton">The button that should be selected by default</param>
		/// <returns>The index of the button that was pressed</returns>
		public static int Show(string message, string[] buttons, int acceptButton, int cancelButton, Icons icon, int defaultButton)
		{
			if (defaultButton >= buttons.Length)
				throw new ArgumentOutOfRangeException("The default buttons is outside the range of available buttons.");

			if (defaultButton < 0)
				defaultButton = buttons.Length - 1;

			message = StringParser.Parse(message);

			using (MsgBox msgBox = new MsgBox(Application.ProductName))
			{
				msgBox.lblMessage.Text = message;
				msgBox.acceptButton = acceptButton;
				msgBox.cancelButton = cancelButton;
				msgBox.ShowCustomButton(buttons);
				msgBox.InitIcon(icon);
				msgBox.pbxIcon.Image = new Bitmap(msgBox.frmIcon.ToBitmap(), 38, 38);
				SetWidth(msgBox);
				SetHeight(msgBox, message);
				msgBox.ShowDialog(MessageService.MainForm);
				return msgBox.Result;
			}
		}
		/// <summary>
		/// Show a message box with a custom button.
		/// </summary>
		/// <param name="message">The message to show</param>
		/// <param name="button">A string of text for a custom button</param>
		/// <param name="acceptButton">Indicates the button that is the Forms AcceptButton</param>
		/// <param name="cancelButton">Indicates the button that is the Forms CancelButton</param>
		/// <param name="icon">The icon to show</param>
		/// <returns>A <see cref="DialogResult"/> indicates the users selection</returns>
		public static int Show(string message, string button, int acceptButton, int cancelButton, Icons icon)
		{
			message = StringParser.Parse(message);
			using (MsgBox msgBox = new MsgBox(Application.ProductName))
			{
				msgBox.lblMessage.Text = message;
				msgBox.acceptButton = acceptButton;
				msgBox.cancelButton = cancelButton;
				msgBox.ShowCustomButton(new string[] { button });
				msgBox.InitIcon(icon);
				msgBox.pbxIcon.Image = new Bitmap(msgBox.frmIcon.ToBitmap(), 38, 38);
				SetHeight(msgBox, message);
				msgBox.ShowDialog(MessageService.MainForm);
				return msgBox.Result;
			}
		}

		/// <summary>
		/// Set the height of the form to accomodate the message
		/// </summary>
		/// <param name="msgBox">The MsgBox instance</param>
		/// <param name="message">The message</param>
		static void SetHeight(MsgBox msgBox, string message)
		{
			Size clientSize = msgBox.ClientSize;
			using (Graphics g = msgBox.CreateGraphics())
			{
				int curHeight = msgBox.lblMessage.Height;
				SizeF sizeF = g.MeasureString(message, msgBox.lblMessage.Font, msgBox.lblMessage.Width);
				int newHeight = Size.Ceiling(sizeF).Height;
				if (newHeight > curHeight)
				{
					int adjustedHeight = newHeight - curHeight;
					msgBox.lblMessage.TextAlign = ContentAlignment.TopLeft;
					clientSize.Width = msgBox.ClientSize.Width;
					clientSize.Height += adjustedHeight;
					msgBox.ClientSize = clientSize; ;
				}
				else
				{
					msgBox.lblMessage.TextAlign = ContentAlignment.MiddleLeft;
				}
			}
		}
		/// <summary>
		/// Set the width of the form to accomodate custom buttons
		/// </summary>
		/// <param name="msgBox">The MsgBox instance</param>
		static void SetWidth(MsgBox msgBox)
		{
			if (null == msgBox)
				return;

			int newWidth = 0;

			if (msgBox.customButtons.Count > 0)
			{
				Size clientSize = msgBox.ClientSize;
				int curWidth = msgBox.flpButtons.Width;
				int width = 0;
				foreach (Button btn in msgBox.customButtons)
					width += btn.Width + (btn.Margin.Left + msgBox.flpButtons.Padding.Right + msgBox.flpButtons.Padding.Left);
				newWidth = curWidth;
				if (width > curWidth)
				{
					newWidth = width - curWidth;
					clientSize.Height = msgBox.ClientSize.Height;
					clientSize.Width += newWidth;
					msgBox.ClientSize = clientSize; ;
				}
			}
		}
		#endregion

		#region Methods

		private void ShowOKButton()
		{
			btnOK = new Button();
			btnOK.Text = "&OK";
			btnOK.Size = new System.Drawing.Size(90, 28);
			btnOK.UseVisualStyleBackColor = true;
			btnOK.Font = new Font(fontPrototype, FontStyle.Regular);
			btnOK.Click += new EventHandler(btnOK_Click);
			flpButtons.Controls.Add(btnOK);
		}

		private void ShowAbortButton()
		{
			btnAbort = new Button();
			btnAbort.Text = "&Abort";
			btnAbort.Size = new System.Drawing.Size(90, 28);
			btnAbort.UseVisualStyleBackColor = true;
			btnAbort.FlatStyle = FlatStyle.System;
			btnAbort.Font = new Font(fontPrototype, FontStyle.Regular);
			btnAbort.Click += new EventHandler(btnAbort_Click);
			flpButtons.Controls.Add(btnAbort);
		}

		private void ShowRetryButton()
		{
			btnRetry = new Button();
			btnRetry.Text = "&Retry";
			btnRetry.Size = new System.Drawing.Size(90, 28);
			btnRetry.UseVisualStyleBackColor = true;
			btnRetry.FlatStyle = FlatStyle.System;
			btnRetry.Font = new Font(fontPrototype, FontStyle.Regular);
			btnRetry.Click += new EventHandler(btnRetry_Click);
			flpButtons.Controls.Add(btnRetry);
		}

		private void ShowIgnoreButton()
		{
			btnIgnore = new Button();
			btnIgnore.Text = "&Ignore";
			btnIgnore.Size = new System.Drawing.Size(90, 28);
			btnIgnore.UseVisualStyleBackColor = true;
			btnIgnore.FlatStyle = FlatStyle.System;
			btnIgnore.Font = new Font(fontPrototype, FontStyle.Regular);
			btnIgnore.Click += new EventHandler(btnIgnore_Click);
			flpButtons.Controls.Add(btnIgnore);
		}

		private void ShowCancelButton()
		{
			btnCancel = new Button();
			btnCancel.Text = "&Cancel";
			btnCancel.Size = new System.Drawing.Size(90, 28);
			btnCancel.UseVisualStyleBackColor = true;
			btnCancel.FlatStyle = FlatStyle.System;
			btnCancel.Font = new Font(fontPrototype, FontStyle.Regular);
			btnCancel.Click += new EventHandler(btnCancel_Click);
			flpButtons.Controls.Add(btnCancel);
		}

		private void ShowYesButton()
		{
			btnYes = new Button();
			btnYes.Text = "&Yes";
			btnYes.Size = new System.Drawing.Size(90, 28);
			btnYes.UseVisualStyleBackColor = true;
			btnYes.FlatStyle = FlatStyle.System;
			btnYes.Font = new Font(fontPrototype, FontStyle.Regular);
			btnYes.Click += new EventHandler(btnYes_Click);
			flpButtons.Controls.Add(btnYes);
		}

		private void ShowNoButton()
		{
			btnNo = new Button();
			btnNo.Text = "&No";
			btnNo.Size = new System.Drawing.Size(90, 28);
			btnNo.UseVisualStyleBackColor = true;
			btnNo.FlatStyle = FlatStyle.System;
			btnNo.Font = new Font(fontPrototype, FontStyle.Regular);
			btnNo.Click += new EventHandler(btnNo_Click);
			flpButtons.Controls.Add(btnNo);
		}

		private void ShowCustomButton(string[] buttons)
		{
			ShowCustomButton(buttons, buttons.Length - 1);
		}
		private void ShowCustomButton(string[] buttons, int defaultButton)
		{
			if (buttons.Length == 0)
				throw new InvalidOperationException("Showing a custom dialog requires at least one custom button.");

			Button defaultBtn = null;
			// Create the buttons
			for (int i = 0; i < buttons.Length; i++)
			{
				Button btnX = new Button();
				btnX.Text = StringParser.Parse(buttons[i]);
				btnX.Tag = i;
				btnX.Size = new System.Drawing.Size(90, 28);
				btnX.UseVisualStyleBackColor = true;
				btnX.FlatStyle = FlatStyle.System;
				btnX.Font = new Font(fontPrototype, FontStyle.Regular);
				btnX.Click += new EventHandler(btnCusto_Click);
				using (Graphics g = this.CreateGraphics())
				{
					SizeF btnSize = g.MeasureString(btnX.Text, btnX.Font);
					btnX.Width = Math.Max(btnX.Width, ((int)Math.Ceiling(btnSize.Width / 8.0) + 1) * 8);
				}
				customButtons.Add(btnX);
				if (defaultButton == i)
					defaultBtn = btnX;
			}

			if (acceptButton >= 0)
				AcceptButton = customButtons[acceptButton];

			if (cancelButton >= 0)
				CancelButton = customButtons[cancelButton];

			defaultBtn.Select();

			// Add the buttons in reverse order so they show left to right
			for (int i = buttons.Length - 1; i >= 0; i--)
				this.flpButtons.Controls.Add(customButtons[i]);
		}

		private void InitButtons(Buttons buttons)
		{
			InitButtons(buttons, -1);
		}
		private void InitButtons(Buttons buttons, int defaultButton)
		{
			if (buttons == Buttons.AbortRetryIgnore)
			{
				ShowIgnoreButton();
				ShowRetryButton();
				ShowAbortButton();
				switch (defaultButton)
				{
					case 0:
						this.btnIgnore.Select();
						break;
					case 1:
						this.btnRetry.Select();
						break;
					default:
						this.btnAbort.Select();
						break;
				}
			}

			if (buttons == Buttons.OK)
			{
				ShowOKButton();
			}

			if (buttons == Buttons.OKCancel)
			{
				ShowCancelButton();
				ShowOKButton();
				switch (defaultButton)
				{
					case 1:
						this.btnCancel.Select();
						break;
				}
			}

			if (buttons == Buttons.RetryCancel)
			{
				ShowCancelButton();
				ShowRetryButton();
				switch (defaultButton)
				{
					case 1:
						this.btnRetry.Select();
						break;
				}
			}

			if (buttons == Buttons.YesNo)
			{
				ShowNoButton();
				ShowYesButton();
				switch (defaultButton)
				{
					case 1:
						this.btnYes.Select();
						break;
				}
			}

			if (buttons == Buttons.YesNoCancel)
			{
				ShowCancelButton();
				ShowNoButton();
				ShowYesButton();
				switch (defaultButton)
				{
					case 1:
						this.btnNo.Select();
						break;
					case 2:
						this.btnYes.Select();
						break;
				}
			}
		}

		private void InitIcon(Icons icon)
		{
			if (MessageService.DoBeep)
			{
				if (icon == Icons.Error)
					MessageService.MessageBeep(30);

				else if (icon == Icons.Warning)
					MessageService.MessageBeep(30);

				else MessageService.MessageBeep(0);
			}

			frmIcon = icons[icon];
		}

		/// <summary>
		/// Performs the KeyDown action
		/// </summary>
		/// <param name="e">KeyEventArgs</param>
		protected override void OnKeyDown(KeyEventArgs e)
		{
			if (cancelButton == -1 && e.KeyCode == Keys.Escape)
				this.Close();
		}


		#endregion

		#region Event Handlers

		void btnCusto_Click(object sender, EventArgs e)
		{
			Button btnX = (Button)sender;
			this._result = (int)(btnX).Tag;
			this.Close();
		}

		void btnOK_Click(object sender, EventArgs e)
		{
			this.DialogResult = DialogResult.OK;
			this.Close();
		}

		void btnAbort_Click(object sender, EventArgs e)
		{
			this.DialogResult = DialogResult.Abort;
			this.Close();
		}

		void btnRetry_Click(object sender, EventArgs e)
		{
			this.DialogResult = DialogResult.Retry;
			this.Close();
		}

		void btnIgnore_Click(object sender, EventArgs e)
		{
			this.DialogResult = DialogResult.Ignore;
			this.Close();
		}

		void btnCancel_Click(object sender, EventArgs e)
		{
			this.DialogResult = DialogResult.Cancel;
			this.Close();
		}

		void btnYes_Click(object sender, EventArgs e)
		{
			this.DialogResult = DialogResult.Yes;
			this.Close();
		}

		void btnNo_Click(object sender, EventArgs e)
		{
			this.DialogResult = DialogResult.No;
			this.Close();
		}

		#endregion
	}
	#endregion
}